﻿using Bll;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace HouseType_API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class HouseController : ControllerBase
    {
        private readonly houseBll bll;

        public HouseController(houseBll bll)
        {
            this.bll = bll;
        }

        /// <summary>
        /// 房型添加
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult HouseTypeAdd(houseModel info)
        {
            try
            {
                int res = bll.HouseTypeAdd(info);
                return Ok(new
                {
                    data = res
                });

            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 房型显示查询
        /// </summary>
        /// <param name="indexs"></param>
        /// <param name="counts"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult HouseTypeList(int pageindex = 1, int pagesize = 2)
        {
            try
            {
                int indexs = 0;
                int counts = 0;
                var list = bll.HouseTypeList(out indexs, out counts, pageindex, pagesize);
                return Ok(new
                {
                    data = list,
                    indexs = indexs,
                    counts = counts
                });
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="h_id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult DeleteInfo(int h_id)
        {
            try
            {
                var list = bll.DeleteInfo(h_id);
                return Ok(new
                {
                    data = list
                });
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="h_state"></param>
        /// <param name="h_id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult UplowState(int h_state, int h_id)
        {
            try
            {
                var list = bll.UplowState(h_state, h_id);
                return Ok(new
                {
                    data = list
                });
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
